package com.demo.dubbo;

import java.lang.reflect.Proxy;

/**
 * @author 许路路
 */
public class EchoServiceTest {

    public static void main(String[] args) {
        MyEchoService echoService = new MyEchoServiceImpl();
        Class<?>[] clazz = echoService.getClass().getInterfaces();
        Class<?>[] interfaces = new Class<?>[clazz.length + 1];
        interfaces[0] = IEchoService.class;
        for (int i = 1; i <= clazz.length; i++) {
            interfaces[i] = clazz[i - 1];
        }
        Object obj = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, new MyInvocationHandler(echoService));
        //正常调用
        MyEchoService myEchoService = (MyEchoService) obj;
        String res = myEchoService.echo("正常方法");
        System.out.println("........." + res);
        //回声测试
        IEchoService iEchoService = (IEchoService) obj;
        String echoRes = iEchoService.$hello("回声测试");
        System.out.println("........." + echoRes);
    }
}
